package bite;

/**
 * Creared with IntelliJ IDEA.
 * Description:【进制转换】给定一个十进制数M，以及需要转换的进制数N。将十进制数M转化为N进制数
 * User:yxd
 * Date:2022-03-26
 * Time:16:58
 */
import java.util.Scanner;
public class Day4_2{
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int M = input.nextInt();
        int N = input.nextInt();
        System.out.println(toN(M, N));
        System.out.println(toN1(M, N));

    }
    public static String toN(int m,int n){
        if(m == 0) return String.valueOf(0);
        if(n == 10) return String.valueOf(m);
        boolean flg = false;
        StringBuilder sb = new StringBuilder();
        String s = "0123456789ABCDEF";//直接提供可拼接的
        if(m < 0){
            flg = true;
            m = -m;//负数
        }
        while(m != 0){
            sb.append(s.charAt(m % n));
            m /= n;
        }
        if (flg){
            sb.append('-');
        }
        sb.reverse();
        return sb.toString();

    }
    public static String toN1(int m,int n){//有点小麻烦
        if(m == 0) return String.valueOf(0);
        if(n == 10) return String.valueOf(m);
        int w = 1;
        if(m < 0){
            w = -1;
            m = -m;
        }
        StringBuilder sb = new StringBuilder();
        while(m != 0){
            int a = m % n;
            m /= n;
            if(a >= 10){
                int b = a - 10;
                char c = (char) ('A' + b);
                sb.append(c);
            }else{
                sb.append(a);
            }
        }
        if(w == -1){
            sb.append('-');
        }
        sb.reverse();
        return sb.toString();

    }
}
